package com.xiaolei48.service;

import com.xiaolei48.entity.Foods;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 菜品信息 业务逻辑接口
 */
@Service
public interface FoodsService {

    /**
     * 添加菜品信息
     * @param foods
     * @return
     */
    @CircuitBreaker(name = "menuService", fallbackMethod = "addFoodsFallback")
    boolean doAddFoodsInfo(Foods foods);

    /**
     * 修改菜品信息
     * @param foods
     * @return
     */
    @CircuitBreaker(name = "menuService", fallbackMethod = "modifyFoodsFallback")
    boolean doModifyFoodsInfo(Foods foods);

    /**
     * 删除菜品信息
     * @param foods
     * @return
     */
    @CircuitBreaker(name = "menuService", fallbackMethod = "deleteFoodsFallback")
    boolean doDeleteFoodsInfo(Foods foods);

    /**
     * 获取菜品信息
     * @param foods
     * @return
     */
    @CircuitBreaker(name = "menuService", fallbackMethod = "getFoodsInfoFallback")
    Foods doGetFoodsInfo(Foods foods);

    /**
     * 获取菜品列表
     * @return
     */
    @CircuitBreaker(name = "menuService", fallbackMethod = "getFoodsInfoListFallback")
    List<Foods> doGetFoodsInfoList();

    /**
     * 查询菜品列表
     * @param foods
     * @return
     */
    @CircuitBreaker(name = "menuService", fallbackMethod = "queryFoodsInfoListFallback")
    List<Foods> doQueryFoodsInfoList(Foods foods);

    // 定义 fallback 方法（添加详细日志）
    default boolean addFoodsFallback(Foods foods, Throwable t) {
        System.err.println("【Service熔断】添加菜品降级：" + t.getClass().getName() + " - " + t.getMessage());
        t.printStackTrace();
        return false;
    }

    default boolean modifyFoodsFallback(Foods foods, Throwable t) {
        System.err.println("【Service熔断】修改菜品降级：" + t.getClass().getName() + " - " + t.getMessage());
        return false;
    }

    default boolean deleteFoodsFallback(Foods foods, Throwable t) {
        System.err.println("【Service熔断】删除菜品降级：" + t.getClass().getName() + " - " + t.getMessage());
        return false;
    }

    default Foods getFoodsInfoFallback(Foods foods, Throwable t) {
        System.err.println("【Service熔断】获取菜品降级：" + t.getClass().getName() + " - " + t.getMessage());
        return null;
    }

    default List<Foods> getFoodsInfoListFallback(Throwable t) {
        System.err.println("【Service熔断】获取列表降级：" + t.getClass().getName() + " - " + t.getMessage());
        return null;
    }

    default List<Foods> queryFoodsInfoListFallback(Foods foods, Throwable t) {
        System.err.println("【Service熔断】查询列表降级：" + t.getClass().getName() + " - " + t.getMessage());
        return null;
    }
}